package com.survey.Controller;

import com.survey.pojo.data.SurveyDO;
import com.survey.pojo.vo.LinkVO;
import com.survey.pojo.vo.SurveyVO;
import com.survey.service.SurveyService;
import com.survey.utils.DataUtils;
import com.survey.utils.PageBean;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.Date;


@Controller
public class SurveylistController {
    @Autowired
    SurveyService surveyService;

    @RequestMapping("/Survey_list")
    public String Survey_listPage(Integer pageCode, SurveyVO surveyVO, Model model) throws Exception {
        surveyVO.setPageSize(10);
        surveyVO.setSize(5);
        surveyVO.setIsopen(1);
        surveyVO.setPageCode(DataUtils.getPageCode(pageCode+""));
        PageBean<SurveyDO> result = surveyService.listSurveyisopen1(surveyVO);
        int i=0;
        for (SurveyDO survey : result.getList()) {
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd日 HH时mm分ss秒");
                String createDate = sdf.format(survey.getCreatedate());
                String endDate = sdf.format(survey.getEndtime());
                SurveyDO surveyDO=new SurveyDO();
                BeanUtils.copyProperties(surveyDO,survey);
                surveyDO.setDate1(createDate);
                surveyDO.setDate2(endDate);
                result.getList().set(i,surveyDO);
                i++;
        }
        model.addAttribute("pageBean",result);
        return "Survey_list.jsp";
    }
}
